// TabSheet.cpp : implementation file
//

#include "TabSheet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTabSheet

CTabSheet::CTabSheet()
{
}

CTabSheet::~CTabSheet()
{
}


BEGIN_MESSAGE_MAP(CTabSheet, CTabCtrl)
	//{{AFX_MSG_MAP(CTabSheet)
	ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTabSheet message handlers

void CTabSheet::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int index = this->GetCurSel();
	int nmax = this->GetItemCount();
	for(int i = 0 ;i<nmax;i++)
	{
		m_pDlg[i]->ShowWindow(SW_HIDE);
	}
	m_pDlg[index]->ShowWindow(SW_SHOW);
	*pResult = 0;
}

bool CTabSheet::AddPage(CDialog * pdlg, UINT ndlgType,char * cztabName)
{
	pdlg->Create(ndlgType,this);
	m_pDlg[this->GetItemCount()] = pdlg;
	InsertItem(this->GetItemCount(),cztabName);
	return true;
}

bool CTabSheet::ShowTab()
{
	RECT rectTitle;
	RECT rectContents;
	//this->GetWindowRect(&rectContents);
	this->GetClientRect(&rectContents);
	this->GetItemRect(0,&rectTitle);
	int nmax = this->GetItemCount();
	int x = rectTitle.left;
	int y = rectTitle.bottom + 1;
	
	int cx = rectContents.right - x - 2;
	int cy = rectContents.bottom - y - 2;

	for(int i = 0 ;i<nmax;i++)
	{
		m_pDlg[i]->SetWindowPos(&wndBottom,x,y,
			cx,cy,SWP_HIDEWINDOW);
		//m_pDlg[i]->ShowWindow(SW_SHOW);
	}
	m_pDlg[0]->ShowWindow(SW_SHOW);
	return true;
}

